﻿/*
 * Programer: JR Padfield
 * Description: Handles Main Menu operations.
 * Version: 1
 * Date: 12/17/13 * 
 */

using System;
using TheWorldLibrary.GameStates;
using Microsoft.Xna.Framework;
using TheWorldLibrary.Controls;
using Microsoft.Xna.Framework.Content;
using TheWorld.Global;
using TheWorld.Networking;

namespace TheWorld.GameScreens
{
    public class MainMenuScreen : BaseGameState
    {
        #region Field Region

        string status;

        Button btnLogin, btnRegister, btnOptions, btnCredits, btnExit;

        #endregion

        #region Property Region


        #endregion

        #region Constructor Region

        public MainMenuScreen(Game game, GameStateManager manager)
            : base(game, manager)
        {
        }

        #endregion

        #region XNA Method Region

        public override void Initialize()
        {
            base.Initialize();
        }

        protected override void LoadContent()
        {
            ContentManager Content = GameRef.Content;
            base.LoadContent();

            btnLogin = new Button(GfxManager.Instance.Buttons[1], GfxManager.Instance.Buttons_H[1], GfxManager.Instance.Buttons_C[1], new Vector2(362, 300), true);
            btnLogin.Color = Color.Black;
            btnLogin.Clicked += new EventHandler(btnLoginClick);
            ControlManager.Add(btnLogin);

            btnRegister = new Button(GfxManager.Instance.Buttons[2], GfxManager.Instance.Buttons_H[2], GfxManager.Instance.Buttons_C[2], new Vector2(362, 370), true);
            btnRegister.Color = Color.Black;
            btnRegister.Clicked += new EventHandler(btnRegisterClick);
            ControlManager.Add(btnRegister);

            btnOptions = new Button(GfxManager.Instance.Buttons[3], GfxManager.Instance.Buttons_H[3], GfxManager.Instance.Buttons_C[4], new Vector2(362, 440), true);
            btnOptions.Color = Color.Black;
            btnOptions.Clicked += new EventHandler(btnOptionsClick);
            ControlManager.Add(btnOptions);

            btnCredits = new Button(GfxManager.Instance.Buttons[4], GfxManager.Instance.Buttons_H[4], GfxManager.Instance.Buttons_C[4], new Vector2(362, 510), true);
            btnCredits.Color = Color.Black;
            btnCredits.Clicked += new EventHandler(btnCreditsClick);
            ControlManager.Add(btnCredits);

            btnExit = new Button(GfxManager.Instance.Buttons[5], GfxManager.Instance.Buttons_H[5], GfxManager.Instance.Buttons_C[5], new Vector2(362, 580), true);
            btnExit.Color = Color.Black;
            btnExit.Clicked += new EventHandler(btnExitClick);
            ControlManager.Add(btnExit);

        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            status = Network.Instance.TcpClient.ConnectionStatus.ToString();

            ControlManager.Update(gameTime, PlayerIndex.One);
        }

        public override void Draw(GameTime gameTime)
        {
            GameRef.SpriteBatch.Begin();

            base.Draw(gameTime);

            GameRef.SpriteBatch.DrawString(GfxManager.Instance.FONT_TEXTURE[1], "Network Connection: " + status, new Vector2(10, 10), Color.White);

            ControlManager.Draw(GameRef.SpriteBatch);

            GameRef.SpriteBatch.End();
        }

        #endregion

        #region MainMenu Method Region

        private void btnLoginClick(object sender, EventArgs e)
        {
            Transition(ChangeType.Change, GameRef.LoginScreen);
        }

        private void btnRegisterClick(object sender, EventArgs e)
        {
            Transition(ChangeType.Change, GameRef.RegisterScreen);
        }

        private void btnOptionsClick(object sender, EventArgs e)
        {

        }

        private void btnCreditsClick(object sender, EventArgs e)
        {
            //Transition(ChangeType.Push, GameRef.CreditScreen);
        }

        private void btnExitClick(object sender, EventArgs e)
        {
            Network.Instance.ShutDown();
            GameRef.Exit();
        }

        #endregion
    }
}
